package com.example.mapper;

import com.example.entity.Zongxiang;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ZongxiangMapper {

    // 根据ID查询纵向课题
    @Select("select * from Zongxiang where id = #{id}")
    Zongxiang selectById(Integer id);

    // 插入新的纵向课题
    @Insert("insert into Zongxiang values (null,#{pnumber},#{pid},#{plevel},#{amount},#{department},#{type},now(),#{records},#{par},#{leader},#{account},now(),#{certifice},#{report},now(),#{teaId})")
    void insert(Zongxiang zongxiang);

    // 根据ID更新纵向课题
    @Update("<script> " + "update Zongxiang " + "<set> " + "<if test='pnumber != null'> " + "pnumber = #{pnumber}, " + "</if> " + "<if test='pid != null'> " + "pid = #{pid}, " + "</if> " + "<if test='amount != null'> " + "amount = #{amount}, " + "</if> " + "<if test='plevel != null'>" + "plevel = #{plevel}, " + "</if>" + "<if test='department != null'> " + "department = #{department}, " + "</if> " + "<if test='type != null'> " + "type = #{type}, " + "</if> " + "<if test='records != null'> " + "records = #{records}, " + "</if> " + "<if test='par != null'> " + "par= #{par}, " + "</if> " + "<if test='leader != null'> " + "leader = #{leader}, " + "</if> " + "<if test='account != null'> " + "account = #{account}, " + "</if> " + "<if test='certifice != null'> " + "certifice = #{certifice}, " + "</if> " + "<if test='report != null'> " + "report = #{report} " + "</if> " + "</set>" + "where id=#{id}" + "</script>")
    void updateById(Zongxiang zongxiang);

    // 根据ID删除纵向课题
    @Delete("delete from Zongxiang where id= #{id}")
    void deleteById(Integer id);

    // 根据条件查询所有纵向课题
    @Select("<script>" + "select * from Zongxiang <where> "+ "<if test='teaId !=null'> " + "and tea_id = #{teaId}"+ "</if> "+ "<if test='pid !=null'> " + "and pid like concat('%',#{pid},'%')"+ "</if> "+ "<if test='pnumber !=null'> " + "and pnumber like concat('%',#{pnumber},'%')"+ "</if> " + "<if test='rdates !=null'> " + "and rdate &gt;= '${rdates} 00:00:00' and rdate &lt;= '${rdates} 23:59:59'" + "</if> " + "</where> "+ "</script>")
    List<Zongxiang> selectAll(Zongxiang zongxiang);
}